﻿using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

using com.fly.sms;

namespace com.fly.sms
{
    public class SqlQueryAction:BaseAction
    {
        public SqlQueryAction(HttpContext contextTemp)
        {
            this.context = contextTemp;
        }
        public override void excute()
        {
            string json = "";
            string sql = context.Request["sql"];
            if(StringUtil.isEmpty(sql)){
                ht.Add("responseCode", "500");
                ht.Add("responseData", "请输入要查询的sql参数");
                json = JsonConvert.SerializeObject(ht);
                context.Response.Write(json);
                return;
            }
            try {
                DataTable rst = Db.find(sql, startRow, pagePerSize);
                
                ht.Add("responseData", rst);
                ht.Add("responseCode", "200");
                json = JsonConvert.SerializeObject(ht);
                context.Response.Write(json);  
            }catch(Exception e){
                ht.Add("responseData", e.Message);
                ht.Add("responseCode", "500");
                json = JsonConvert.SerializeObject(ht);
                context.Response.Write(json);  
            }
                    
        }
    }
}